﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;

namespace GradienLabelComponent
{
    class GradientLabelActionList : DesignerActionList 
    {

        GradientLabel glabel;
        DesignerActionUIService designerActionUIServise;
        public GradientLabelActionList(IComponent component) : base(component)
        {
            glabel = component as GradientLabel;
            this.designerActionUIServise = GetService(typeof(DesignerActionUIService)) as DesignerActionUIService;
        }

        private PropertyDescriptor GetPropertyByName(string propName)
        {
            PropertyDescriptor prop = TypeDescriptor.GetProperties(glabel)[propName];
            if (prop == null)
            {
                throw new ArgumentException("Property is not exist", propName);
            }
            return prop;
        }

        public Color StartColor
        {
            get { return glabel.StartColor; }
            set { GetPropertyByName("StartColor").SetValue(glabel, value); }
        }

        public Color EndColor
        {
            get { return glabel.EndColor; }
            set { GetPropertyByName("EndColor").SetValue(glabel, value); }
        }
        public void InvertColors()
        {
            Color tmp = glabel.EndColor;
            glabel.EndColor = glabel.StartColor;
            glabel.StartColor = tmp;
            designerActionUIServise.Refresh(glabel);
        }
        public override DesignerActionItemCollection GetSortedActionItems()
        {
            DesignerActionItemCollection items = new DesignerActionItemCollection();

            items.Add(new DesignerActionHeaderItem("Properties", "Properties"));
            items.Add(new DesignerActionHeaderItem("Methods", "Methods"));
            items.Add(new DesignerActionHeaderItem("Information", "Information"));

            items.Add(new DesignerActionPropertyItem("StartColor", "Start color", "Properties", "Start gradient color"));
            items.Add(new DesignerActionPropertyItem("EndColor", "End color", "Properties", "End gradient color"));

            items.Add(new DesignerActionMethodItem(this, "InvertColors", "Invert Colors", "Methods", "Inverting gradient colors", true));

            string info = String.Format("Size is {0}x{1}", glabel.Width, glabel.Height);
            items.Add(new DesignerActionTextItem(info, "Information"));
            return items;
        }
    }
}
